require.config({
    paths: {
        'vue': '../encaptool/encvue',
        'iview': '../utiltool/iview/iview',
        'jquery': '../utiltool/jquery/jquery.min',
        'router': '../encaptool/encarouter',
        'axios': '../encaptool/encaxios'
    },
    shim: {
        iview: [
            'vue'
        ]
    }
})
require(['vue', 'iview', 'jquery', 'router', 'axios'], function(Vue, iview, $, Router, axios) {
    Vue.use(iview);
    new Vue({
        el: '#app',
        data() {
            return {
                phone: '15633165503',
                password: '123456',
                code: '',
                Client: '',
                trueValue: '',
                loginShow: true,
                isShow: false,
                pw: '',
                newpw: '',
                // newpwsure: '',
                telephone: '',
            }
        },
        mounted() {
            this.getValue();
        },
        methods: {
            getValue: function() {
                var setting = {
                    method: "GET",
                    url: "/yf/public/index/Code/getValue/"
                }
                axios.call(this, function(res) {
                    if (res.code === 0) {
                        this.trueValue = res.data;
                    }
                }.bind(this), {
                    setting
                })

            },
            getImage() {
                this.$refs.code.src = "/yf/public/index/Code/imageCode/";
                setTimeout(function() {
                    this.getValue();
                }.bind(this), 200);
            },
            changePassword: function() {
                this.loginShow = false;
                this.isShow = true;
            },
            changeSure: function() {
                var setting = {
                    method: "POST",
                    url: "/YF/public/index/Service/changePassword"
                }
                var data = {
                    pw: this.pw,
                    newpw: this.newpw,
                    telephone: this.telephone,
                }
                axios.call(this, function(res) {
                    if (res.code == 0) {
                        this.$Notice.success({
                            title: '修改成功！'
                        });
                        return;
                    } else if (this.pw == null || this.newpw == null || this.telephone == null) {
                        this.$Notice.error({
                            title: '不能为空！'
                        });
                    } else {
                        this.$Notice.error({
                            title: '初始密码错误，无法修改！'
                        });
                        return;
                    }

                }.bind(this), {
                    setting,
                    data
                })
            },
            login: function() {
                this.code = this.code.toLowerCase();
                if (this.code != this.trueValue) {
                    this.$Notice.error({
                        title: '验证码不正确'
                    });
                    return;
                }
                var setting = {
                    method: "POST",
                    url: "/YF/public/index/Service/login"
                }
                var data = {
                    phone: this.phone,
                    password: this.password
                }
                axios.call(this, function(res) {
                    if (res.code === 400) {
                        this.$Notice.error({
                            title: '用户名或密码不正确'
                        });
                        return;
                    }
                    location.href = "/YF/public/page/index"
                }.bind(this), {
                    setting,
                    data
                })
            }
        },
    });
});